package com.dom.domweb.modular.controller;

import com.dom.common.model.vo.sale.*;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.common.TabPager;
import com.dom.domweb.modular.service.MarketSaleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 销售单控制器
 * @author zhuwei
 * @Date 2018-12-03
 */
@Slf4j
@RestController
@RequestMapping("/sale")
public class MarketSaleController {

    @Autowired
    private MarketSaleService marketSaleService;

    /**
     * 销售单查询列表
     * @param limit 每页行数
     * @param page 当前页数
     * @param exchStartDate 交易开始时间
     * @param exchEndDate 交易结束时间
     * @param saleStartDate 销售开始时间
     * @param saleEndDate 销售结束时间
     * @param custCode 客户编码
     * @param custName 客户名称
     * @param saleType 销售类型
     * @return
     */
    @RequestMapping("/getMarketSaleList")
    public TabPager getMarketSaleList(@RequestParam("limit")int limit,
                                       @RequestParam("page")int page,
                                       @RequestParam("exchStartDate") String exchStartDate,
                                       @RequestParam("exchEndDate")String exchEndDate,
                                       @RequestParam("saleStartDate")String  saleStartDate,
                                       @RequestParam("saleEndDate")String  saleEndDate,
                                       @RequestParam("custCode")String  custCode,
                                       @RequestParam("custName")String  custName,
//                                      @RequestParam("sourBillType")String  sourBillType,
                                       @RequestParam("saleType")String  saleType) {
        M039R request = new M039R();
        request.setSaleType(saleType);
        request.setCustCode(custCode);
        request.setCustName(custName);
//        request.setSourBillType(sourBillType);
        request.setExchEndDate(exchEndDate);
        request.setExchStartDate(exchStartDate);
        request.setSaleEndDate(saleEndDate);
        request.setSaleStartDate(saleStartDate);
        request.setPn(page);
        request.setPs(limit);
        M039A result = marketSaleService.getMarketSaleList(request);
        return new TabPager(result.getSaleInfoData(),result.getTotalNum());
    }

    /**
     * 销售订新增
     * @param request
     * @return
     */
    @RequestMapping("/insertMarketSale")
    public RspModel insertMarketSale(@RequestBody M030R request){
        String id = marketSaleService.insertMarketSale(request);
        return new RspModel(id);
    }

    /**
     * 销售单明细查询
     * @param id
     * @return
     */
    @RequestMapping("/toUpdateMarketSalePage")
    public RspModel toUpdateMarketSalePage(@RequestParam("id") String id){
        M033A result = marketSaleService.findUpdateMarketSale(id);
        return new RspModel(result);
    }

    /**
     * 销售单删除
     * @param id
     * @return
     */
    @RequestMapping("/marketSaleDel")
    public RspModel marketSaleDel(@RequestParam("id") String id){
        boolean isTure = marketSaleService.marketSaleDel(id);
        RspModel model = new RspModel("RSP000000","销售单删除成功！");
        if(!isTure){
            model.setRspCode("RSP000001");
            model.setRspMsg("销售单删除失败！");
        }
        return model;
    }

    /**
     * 销售单修改
     * @param request
     * @return
     */
    @RequestMapping("/marketSaleModify")
    public RspModel marketSaleModify(@RequestBody M032R request){
        return marketSaleService.marketSaleModify(request);
    }
}
